/*
 * @Author: silence
 * @Date: 2022-04-27 11:51:00
 * @LastEditors: silence silence9685@163.com
 * @LastEditTime: 2023-04-19 19:45:51
 * @Description: 自定义AppBar
 */

import 'package:flutter/material.dart';

class SilAppBar extends StatefulWidget implements PreferredSizeWidget {
  /**导航条高度 */
  final double navBarHeight;

  /**AppBar背景颜色，默认白色 */
  final Color? backgroundColor;

  /**左边按钮 */
  final Widget? leadingWidget;

  /**中间title */
  final Widget? titleWidget;

  /**右边按钮 */
  final Widget? trailingWidget;

  /**导航分割线，默认不显示 */
  final bool? underlineHide;

  const SilAppBar(
      {Key? key,
      this.navBarHeight = 44,
      this.backgroundColor = Colors.black,
      this.leadingWidget,
      this.titleWidget,
      this.trailingWidget,
      this.underlineHide = true})
      : super(key: key);

  @override
  State<SilAppBar> createState() => _SilAppBarState();

  @override
  Size get preferredSize => new Size.fromHeight(navBarHeight);
}

class _SilAppBarState extends State<SilAppBar> {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: widget.backgroundColor,
      child: SafeArea(
          top: true,
          child: Container(
            height: widget.navBarHeight,
            decoration: (widget.underlineHide == true)
                ? null
                : UnderlineTabIndicator(
                    borderSide:
                        BorderSide(width: 1.0, color: Color(0xFFeeeeee))),
            child: Stack(
              alignment: Alignment.center,
              children: [
                Positioned(
                    left: 0, child: Container(child: widget.leadingWidget)),
                Container(child: widget.titleWidget),
                Positioned(
                    right: 0, child: Container(child: widget.trailingWidget))
              ],
            ),
          )),
    );
  }
}
